#ifndef __RTSP_SERVER_H__
#define __RTSP_SERVER_H__

#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <sys/ipc.h>
#include <sys/msg.h>



#define PROGRAME_VERSION "rtsp server 1.0"
#define RTP_SERVER_NAME "./RtpServer"

#define RTSP_SERVER_VERSION "RTSP/1.0"
#define STRING_END "\r\n"
#define SERVER_INFO "C1-618/1.0.0 (Stream Server Media v2012.03.21)"
#define PUBLIC_INFO "DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, OPTIONS"

#define RESPONSE_OPTIONS "RTSP/1.0 %d %s\r\n"\
    "Server: "SERVER_INFO STRING_END\
    "CSeq: %d"STRING_END\
    "Public: "PUBLIC_INFO STRING_END\
    STRING_END
#define RESPONSE_DESCRIBE "RTSP/1.0 %d %s\r\n"\
    "Server: " SERVER_INFO STRING_END\
    "CSeq: %d" STRING_END\
	"Content-Base: %s" STRING_END\
	"Content-Length: 542" STRING_END\
    STRING_END\
	"v=0" STRING_END\
	"o=- 13290000 1 IN IP4 192.168.1.98" STRING_END\
	"s=Session streamed by \"Object RTSPServer\"" STRING_END\
	"i=H264" STRING_END\
	"t=0 0" STRING_END\
	"a=tool:LIVE555 Streaming Media v2011.07.08" STRING_END\
	"a=type:broadcast" STRING_END\
	"a=control:*" STRING_END\
	"a=range:npt=0-" STRING_END\
	"a=x-qt-text-nam:Session streamed by \"Object RTSPServer\"" STRING_END\
	"a=x-qt-text-inf:H264" STRING_END\
	"m=video 0 RTP/AVP 96" STRING_END\
	"c=IN IP4 0.0.0.0" STRING_END\
	"b=AS:500" STRING_END\
	"a=rtpmap:96 H264/90000" STRING_END\
	"a=fmtp:96 packetization-mode=1;profile-level-id=42000D;sprop-parameter-sets=J0IADapAoPk3AgICQAAAAwBAAAAGeAAAQAAABgAC5zgCAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA,KM4EcgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==" STRING_END\
	//"a=control:track1" STRING_END
#define RESPONSE_SETUP "RTSP/1.0 %d %s\r\n"\
    "CSeq: %d" STRING_END\
	"Transport: %s" STRING_END\
    "Session: %s" STRING_END\
    STRING_END
#define RESPONSE_SETUP_ERROR "RTSP/1.0 %d %s\r\n"\
    "Server: " SERVER_INFO STRING_END\
    "CSeq: %d" STRING_END\
    STRING_END
#define RESPONSE_PLAY "RTSP/1.0 %d %s\r\n"\
    "Server: " SERVER_INFO STRING_END\
    "CSeq: %d" STRING_END\
    "Session: %s" STRING_END\
    "Range: npt=%f-%f" STRING_END\
    STRING_END
#define RESPONSE_PLAY_ERROR "RTSP/1.0 %d %s\r\n"\
    "Server: " SERVER_INFO STRING_END\
    "CSeq: %d" STRING_END\
    STRING_END



#define FILE_MAX_LEN 256
#define STRING_BUF_MAX_LEN 4096
#define MAX_LINE_LENGTH 100
#define MAX_URL_LENGTH 80
#define MAX_SESSION_LENGTH 20

#define MAX_RTST_URL_LEN 256


typedef enum BOOL 
{
	FALSE = 0,
	TRUE = !FALSE
}BOOL;


typedef struct StruRtspCmd
{
    char *pstrCmdName;
    int (*pCmdHandler)(int piClientfd, char *ppstrInfo);
}RtspCmd,*pRtspCmd;



typedef struct StruSessionGlobalInfo
{
	char strClientAddr[20];
	int iCurrentSeq;
	char strCurrentUrl[100];
	int iMarkTcp;
	int iRtpPort;
	int iRtcpPort;
	int bMarkStep;		//0 not; 1 options; 2 describe; 3 setup; 4 play; 5 pause;
	char strCurrentSession[20];
	float iRangeStart;
	float iRangeEnd;
	char strLastRequestTime[20];
}SessionGlobalInfo,*pSessionGlobalInfo;

//rtsp server and rtp programe communication protocol
typedef struct StruRtspToRtp
{
	int iCommand;	//1 setup; 2 play; 3 pause; 100 teardown;
	int iType;	//1 TCP; 2 UDP;
	char strClientAddr[20];	//client connect rtsp server and setup the port
	int iClientPort;	//client port
	char strSession[20];	//client session info
}RtspToRtp,*pRtspToRtp;

//camera informtion
typedef struct StruCameraInfo
{
	int iType;
	char strRealUrl[MAX_RTST_URL_LEN];
	char strVisitUrl[MAX_RTST_URL_LEN];
	int iMsqId;
	char strVideoPath[FILE_MAX_LEN];
	struct StruCameraInfo *next;
}CameraInfo,*pCameraInfo;

//system message queue 
typedef struct StruQueueMsgbuf 
{
	long ltype;	//
	int iCommand;	//0 setup; 1 play; 2 pause; 9 stop; 101 stopcamera; 11 up; 12 down; 13 left; 14 right
	int iMarkTcp;
	char strAddr[20];
	int iPort;
	char strSession[20];
}QueueMsgbuf,*qQueueMsgbuf;


#endif
